

/*
* Copyright @ 2017 com.iflysse.trains
* crm 上午1:31:19
* All right reserved.
*
*/
	
package com.qf.service.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import com.qf.dao.CrmClassDao;
import com.qf.dao.CrmCourseTypeDao;
import com.qf.dao.CrmReferDao;
import com.qf.dto.CrmFollowDto;
import com.qf.dto.CrmReferDto;
import com.qf.pojo.CrmFollow;
import com.qf.pojo.CrmRefer;
import com.qf.pojo.CrmStudent;
import com.qf.pojo.PageRefer;
import com.qf.service.CrmReferService;
import com.qf.utils.DateUtil;

/**
* @desc: crm
* @descripe:XXXX
* @author: 周锐
* @createTime: 2017年7月27日 上午1:31:19
* @history:
* @version: v1.0

*/

public class CrmReferServiceImpl implements CrmReferService {
   private CrmReferDao referdao;
   private CrmClassDao classdao;
   private CrmCourseTypeDao ctd;
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmReferService#addRefer(com.qf.pojo.CrmRefer)
	*/

	
/**
* @param referdao the referdao to set
*/

public void setReferdao(CrmReferDao referdao) {

	this.referdao = referdao;
}

	

	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmReferService#updateRefer(com.qf.pojo.CrmRefer)
	*/

	
	/**
	* @param classdao the classdao to set
	*/
	
	public void setClassdao(CrmClassDao classdao) {
	
		this.classdao = classdao;
	}

	
	/**
	* @param ctd the ctd to set
	*/
	
	public void setCtd(CrmCourseTypeDao ctd) {
	
		this.ctd = ctd;
	}
	
	@Override
	public void addRefer(CrmRefer refer) {

		referdao.addRefer(refer);

	}
	

	@Override
	public void updateRefer(CrmRefer refer) {

		referdao.updateRefer(refer);

	}

	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmReferService#findReferById(java.lang.Long)
	*/

	@Override
	public CrmReferDto findReferById(Long referId) {

		//TODO
		CrmRefer refer = referdao.findReferById(referId);
		CrmReferDto referdto=new CrmReferDto();
		referdto.setReferId(refer.getReferId());
		referdto.setStaffName(refer.getCrmStaff().getStaffName());
		referdto.setStaffId(refer.getCrmStaff().getStaffId());
		referdto.setStuName(refer.getStuName());
		referdto.setTelephone(refer.getTelephone());
		referdto.setQq(refer.getQq());
		referdto.setCreateDate(DateUtil.tranfaceString(refer.getCreateDate()));
		referdto.setIntentionLevel(refer.getIntentionLevel());
		referdto.setCourseName(ctd.findbyId(refer.getCourseTypeId()).getCourseName());
		referdto.setCourseTypeId(refer.getCourseTypeId());
		referdto.setClassName(classdao.findclassbyId(refer.getClassId()).getClassName());
		referdto.setClassId(refer.getClassId());
		referdto.setSource(refer.getSource());
		referdto.setStatus(refer.getStatus());
		referdto.setRemark(refer.getRemark());
		return referdto;

	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmReferService#findReferByPage(int, int)
	*/
		
	@Override
	public PageRefer findReferByPage(int page, int size) {
		List<CrmRefer> list = referdao.findReferByPage(page, size);
		List<CrmReferDto> referdtos=new ArrayList<>();
		for(CrmRefer refer:list){
			CrmReferDto referdto=new CrmReferDto();
			referdto.setReferId(refer.getReferId());
			referdto.setStaffName(refer.getCrmStaff().getStaffName());
			referdto.setStaffId(refer.getCrmStaff().getStaffId());
			referdto.setStuName(refer.getStuName());
			referdto.setTelephone(refer.getTelephone());
			referdto.setQq(refer.getQq());
			referdto.setCreateDate(DateUtil.tranfaceString(refer.getCreateDate()));
			referdto.setIntentionLevel(refer.getIntentionLevel());
			referdto.setCourseName(ctd.findbyId(refer.getCourseTypeId()).getCourseName());
			referdto.setCourseTypeId(refer.getCourseTypeId());
			referdto.setClassName(classdao.findclassbyId(refer.getClassId()).getClassName());
			referdto.setClassId(refer.getClassId());
			referdto.setSource(refer.getSource());
			referdto.setStatus(refer.getStatus());
			referdto.setRemark(refer.getRemark());
			referdtos.add(referdto);
		}
		int count = referdao.findReferCount();
		int totalpage=(count-1)/size+1;
		return new PageRefer(page, size, totalpage, referdtos);
			
	}



	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmReferService#findReferuseId(java.lang.Long)
	*/
		
	@Override
	public CrmRefer findReferuseId(Long referId) {
		
		//TODO
		return referdao.findReferById(referId);
			
	}



	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmReferService#addFollow(com.qf.pojo.CrmFollow)
	*/
		
	@Override
	public void addFollow(CrmFollow follow) {
		
		referdao.addFollow(follow);
			
	}



	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmReferService#findfollowbyrefer(java.lang.Long)
	*/
		
	@Override
	public List<CrmFollowDto> findfollowbyrefer(Long referId) {
		
		//TODO
		List<CrmFollow> list = referdao.findfollowbyrefer(referId);
		List<CrmFollowDto> followdtos=new ArrayList<>();
		for(CrmFollow follow:list){
			CrmFollowDto followdto=new CrmFollowDto();
			followdto.setContent(follow.getContent());
			followdto.setFollowTime(DateUtil.tranfaceString(follow.getFollowTime()));
			followdto.setStaffId(follow.getCrmStaff().getStaffId());
			followdto.setStaffName(follow.getCrmStaff().getStaffName());
			followdtos.add(followdto);
		}
		return followdtos;
	}



	
	/*
	*(non-Javadoc)
	* @see com.qf.service.CrmReferService#addCrmStudent(com.qf.pojo.CrmStudent)
	*/
		
	@Override
	public void addCrmStudent(CrmStudent student) {
		
		referdao.addCrmStudent(student);
			
	}

}

	